<?php

/**
 * This is the model class for table "xyh_alumni".
 *
 * The followings are the available columns in table 'xyh_alumni':
 * @property string $id
 * @property string $city_id
 * @property string $school_id
 * @property string $ctime
 * @property string $dtime
 * @property string $status
 * @property string $is_del
 */
class Alumni extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Alumni the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xyh_alumni';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('city_id,ctime, dtime', 'length', 'max'=>10),
                        array('school_id','safe'),
			array('status, is_del', 'length', 'max'=>1),
                        array('parent_id','required'),
                        array('rename','required','message'=>'请填写名称'),
                        array('rename', 'unique', 'message' => '总会已存在!'),
                       // array('domain','safe'),
                    array('banner_url','safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, city_id, school_id, ctime, dtime, status, is_del', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                     'Area' => array(self::BELONGS_TO, 'Area', 'city_id'),
                     'School' => array(self::BELONGS_TO, 'School', 'school_id'),
                     'Activity'=>array(self::HAS_MANY,'Activity','alumni_id'),
                     'News'=>array(self::HAS_MANY,'News','alumni_id'),
                     'Article'=>array(self::HAS_MANY,'Article','alumni_id'),
                     'UserSchool'=>array(self::HAS_MANY,'UserSchool','school_id')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'city_id' => 'City',
			'school_id' => 'School',
			'ctime' => 'Ctime',
			'dtime' => 'Dtime',
			'status' => 'Status',
			'is_del' => 'Is Del',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
                $Sparent_id = Yii::app()->user->parent_id;
                $Salumni_id = Yii::app()->user->Alumni_id;
               
		$criteria=new CDbCriteria;

                 if($Salumni_id && $Sparent_id !=0){
                    $criteria->addCondition("parent_id= {$Salumni_id}");
                }
                elseif ($Salumni_id && $Sparent_id ==0) {
                    $criteria->addCondition("parent_id={$Salumni_id}");
                }
              
               
     
		$criteria->compare('id',$this->id,true);
		$criteria->compare('city_id',$this->city_id,true);
		$criteria->compare('school_id',$this->school_id,true);
		$criteria->compare('ctime',$this->ctime,true);
		$criteria->compare('dtime',$this->dtime,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('is_del',$this->is_del,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
//          public function getCategoryList() 
//        { 
//            $returnArr = $this->findAllByAttributes(array('sign'=>11)); 
//            return CHtml::listData($returnArr, 'id', 'name'); 
//        } 
}